package com.erp.erp_servers.CustomerLog.imp;

import com.erp.erp_dao.CustomerLog.ICustomerLogDAO;
import com.erp.erp_dao.LogDB.ILogDBDao;
import com.erp.erp_entitys.CustomerLog.CustomerLogEntity;
import com.erp.erp_entitys.CustomerLog.CustomerLogExample;
import com.erp.erp_entitys.LogDB.LogDBEntity;
import com.erp.erp_servers.CustomerLog.ICustomerLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ImpCustomerLogService
 * @Description TODO
 * @Author songjizhen
 * @Date 2020-06-29 20:05
 * @Version 1.0
 */
@Service
public class ImpCustomerLogService implements ICustomerLogService {
    @Autowired
    ICustomerLogDAO customerLogDAO;
    @Autowired
    private ILogDBDao logDBDao;

    @Override
    public int insert(CustomerLogEntity record) {
        return customerLogDAO.insert(record);
    }

    @Override
    public List<CustomerLogEntity> selectByExample(CustomerLogExample example) {
        String code=example.getOredCriteria().get(0).getCriteria().get(0).getValue().toString().replace("%","");
        LogDBEntity log =new LogDBEntity();
        log.setTableName("customer");
       // log.setType("update(更新)");
        log.setParams("code="+code);
        List<LogDBEntity> query = logDBDao.query(log);
        List<CustomerLogEntity> list=new ArrayList<>();
        for(int i=0;i<query.size();i++){
            LogDBEntity logdb=query.get(i);
            CustomerLogEntity cle=new CustomerLogEntity();
             cle.setOptioner(logdb.getUserName());
             cle.setType(logdb.getType());
             cle.setOptionTime(logdb.getInTime());
             cle.setContent(logdb.getParams());
             list.add(cle);
        }
        return list;//customerLogDAO.selectByExample(example);
    }
}
